/* 封装ajax */

export const myAjax = function (method, url) {
  return new Promise(function (success, reject) {
    let xhr;
    if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xhr = new XMLHttpRequest();
    } else {
      // code for IE6, IE5
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status == 200) {
        success(JSON.parse(xhr.response));
      }
    };
    xhr.open(method, url);
    xhr.send();
  });
};
